const students  = require('./students')

const searchFunc = (ops) => {
    const obj = JSON.parse(ops.body);
    console.log(ops);
    console.log(obj);
    const res = [];
    const reg = new RegExp(obj[0]);
    const reg2 = new RegExp(obj[1]);
    const len = students.students.student.length;
    for (let i = 0; i < len; i++) {
        if(students.students.student[i].name.match(reg)&&students.students.student[i].id.match(reg2)||
            students.students.student[i].class.match(reg)&&students.students.student[i].sex.match(reg2))
            res.push(students.students.student[i]);
    }
    console.log(res);
    return res;
};
module.exports = {
    path: '/api/search',
    type: 'post',
    func: searchFunc
}